﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tedds_Tool.RulesBase;
using System.Windows.Automation;
using System.IO;
using Tedds_Tool.Automatables;
using CommonInterfaces.Models;
using LEET.CommonInterfaces.Models;

namespace RulesBase.Model
{
    class Implication : IImplication
    {
        public Implication(string name, IList<IInstruction> instructions)
        {
            this.Name = name;
            this.Instructions = instructions;
        }
        
        public void Trigger(AutomationElement ae)
        {
            throw new NotImplementedException();
        }

        public string Name
        {
            get;
            private set;
        }

        public IList<IInstruction> Instructions
        {
            get;
            private set;
        }

        internal static IImplication Load(string name, IInstructionFactory fac, Tedds_Tool.IScriptFinder finder)
        {
            IImplication condition = null;
            using (TextReader reader = finder.FindImplication(name))
            {
                IList<IInstruction> instructions = new List<IInstruction>();
                String ins;
                while ((ins = reader.ReadLine()) != null)
                {
                    instructions.Add(fac.Interpret(ins));
                }
                condition = new Implication(name, instructions);
            }
            return condition;
        }

    }
}
